package chips440.tiles;

import java.applet.Applet;
import java.applet.AudioClip;
import java.awt.image.BufferedImage;
import chips440.internals.Player;
import chips440.main.Types;

/**
 * This is a plain tile with no particular effects on the player. It is,
 * however, the only tile that can have items on it. If an item is present,
 * and the number of that item is > -1. Images for this tile type are named
 * "item<item number>.gif"
 *
 * @author Ryan Hofler
 * @version 0.1
 */
public class NormalTile extends Tile{
    private Types.Item item;
    private BufferedImage image = null;
	private AudioClip pickup;

    /**
     * Make a NormalTile with nothing on it.
     */
    public NormalTile(){
        this.item = null;
        this.image = chips440.main.ResourceCache.getImage("empty");
    }

    /**
     * Make a NormalTile with the specified item on it.
     *
     * @param i the number of the item on this tile
     * @throws IllegalArgumentException if i is not one of the constants
     * specified in chips440.main.Item
     */
    public NormalTile(Types.Item i){
        this.item = i;
        this.image = chips440.main.ResourceCache.getImage(i);
		this.pickup = chips440.main.ResourceCache.getSound("PICKUP.WAV");
    }

    /**
     * Get the item that's stored on this tile, if any
     *
     * @return a Types.Item that this tile holds
     */
    public Types.Item getItem(){
        Types.Item ret_item = this.item;
        this.item = null;
	    pickup.play();
	this.image = chips440.main.ResourceCache.getImage("empty");
        return ret_item;
    }

    public BufferedImage paintSelf(){
        return this.image;
    }

    public synchronized Types.TileAct okToStep(Player player){
        if(this.item == null)
            return Types.TileAct.MOVE;
        return Types.TileAct.ITEM;
    }
}
